<template>
  <div class="layout-padding">
    <div class="layout-padding-auto layout-padding-view">
      <el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList" style="margin-top: 15px">
        <el-form-item :label="$t('report.salesOrder')" prop="checkProcessCode" style="width: 10%">
          <el-input v-model="state.queryForm.checkProcessCode" clearable :placeholder="$t('report.salesOrder')"/>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" plain @click="getDataList">{{$t('btn.search')}}</el-button>
          <el-button type="success" @click="resetQuery"><el-icon><Download /></el-icon>{{$t('report.Import')}}</el-button>
          <el-button icon="upload" type="success" plain>{{$t('report.export')}}</el-button>
          <el-button icon="el-icon-search" type="primary" @click="formDialogRef.openDialog() ">{{$t('report.orderInquiry')}}</el-button>
        </el-form-item>
      </el-form>
      <el-tabs model-value="first">
        <el-tab-pane name="first">
          <template #label>
            <el-icon><calendar/></el-icon>
            <span class="ml-0.5"> {{ $t('report.rawMaterial') }} </span>
          </template>
        </el-tab-pane>
      </el-tabs>
      <el-table :data="state.dataList" v-loading="state.loading" border
                :cell-style="tableStyle.cellStyle" :header-cell-style="tableStyle.headerCellStyle"
                @selection-change="selectionChangHandle" style="width: 100%;height: 100%;"
                @sort-change="sortChangeHandle">
        <el-table-column width="150" prop="socode" :label="$t('report.salesOrder')"  fixed="left" show-overflow-tooltip/>
        <el-table-column width="150" prop="processName" :label="$t('iot.processName')" fixed="left" show-overflow-tooltip/>
        <el-table-column width="200" prop="inputBarcode" :label="$t('report.inputBarcode')" fixed="left" show-overflow-tooltip/>
        <el-table-column width="150" prop="materialCode" :label="$t('wms.materialCode')" fixed="left" show-overflow-tooltip/>
        <el-table-column width="150" prop="materialName" :label="$t('iot.materialName')"show-overflow-tooltip/>
        <el-table-column width="150" prop="attribute1" :label="$t('mes.finishedMateriarcode')" show-overflow-tooltip/>
        <el-table-column width="150" prop="finishedMaterialName" :label="$t('mes.finishedMaterialName')" show-overflow-tooltip/>
        <el-table-column width="300" prop="finishedMaterialSpec" :label="$t('report.finishedMaterialSpec')" show-overflow-tooltip/>
        <el-table-column width="150" prop="consumeQty" :label="$t('report.quantityInvested')" show-overflow-tooltip>
          <template #default="scope">
               <el-tag type="success">
                   {{ scope.row.consumeQty }}
                </el-tag>
           </template>
        </el-table-column>
        <el-table-column width="150" prop="produceQty" :label="$t('report.totalOutput')" show-overflow-tooltip>
          <template #default="scope">
              <el-tag type="primary">
                    {{ scope.row.produceQty }}
              </el-tag>
          </template>
        </el-table-column>
        <el-table-column width="180" prop="receiptCode" :label="$t('report.receiptCode')" show-overflow-tooltip/>
        <el-table-column width="150" prop="customerModel" :label="$t('report.customerModel')" show-overflow-tooltip/>
        <el-table-column width="150" prop="instockOrderNo" :label="$t('report.warehouseEntryNumber')" show-overflow-tooltip/>
        <el-table-column width="200" prop="poOrderNo" :label="$t('report.poOrderNo')" show-overflow-tooltip/>
        <el-table-column width="150" prop="contractNo" :label="$t('report.contractNo')" show-overflow-tooltip/>
        <el-table-column width="150" prop="produceBatch" :label="$t('report.produceBatch')" show-overflow-tooltip/>
        <el-table-column width="150" prop="stockBatch" :label="$t('report.stockBatch')" show-overflow-tooltip/>
        <el-table-column width="200" prop="asnNo" :label="$t('report.asnNo')" show-overflow-tooltip/>
        <el-table-column width="200" prop="supplierName" :label="$t('qms.supplierName')" show-overflow-tooltip/>

      </el-table>
      <pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination"/>
    </div>

    <!-- 编辑、新增  -->
    <form-dialog ref="formDialogRef" @refresh="getDataList(false)"/>

  </div>
</template>

<script setup lang="ts" name="systemQmsProductionCheck">
import {BasicTableProps, useTable} from "/@/hooks/table";

// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// 定义查询字典
import {mesForwardTrace} from "/@/api/platform/mes/mesForwardTrace";

// 定义变量内容
const formDialogRef = ref()
// 搜索变量
const queryRef = ref()

// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)

const state: BasicTableProps = reactive<BasicTableProps>({
  queryForm: {},
  pageList: mesForwardTrace,
  isPage: false
})

//  table hook
const {
  getDataList,
  currentChangeHandle,
  sizeChangeHandle,
  sortChangeHandle,
  downBlobFile,
  tableStyle
} = useTable(state)

// 清空搜索条件
const resetQuery = () => {
  // 清空搜索条件
  queryRef.value?.resetFields()
  // 清空多选
  selectObjs.value = []
  getDataList(false)
}

// 导出excel
const exportExcel = () => {
  downBlobFile('/platform/qmsProductionCheck/export', Object.assign(state.queryForm, {ids: selectObjs}), 'qmsProductionCheck.xlsx')
}

// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
  selectObjs.value = objs.map(({id}) => id);
  multiple.value = !objs.length;
};

</script>